Skip to contentSkip to conversation

Change in openvpn[master]: iservice: make sure directories have trailing \

Openvpn-devel In review d12fk (Code Review) 2 participants 16 messages Oct 31, 2025 – Nov 12, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1761939285000.If28e66fcc3493821f78fd14d432b22b996918e8f@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email

to review the following change.

Change subject: iservice: make sure directories have trailing \
......................................................................

iservice: make sure directories have trailing \

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

---
M src/openvpnserv/common.c

1 file changed, 33 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/1

src/openvpnserv/common.c +33 -6
index d25d9c0..969b8ac 100644
@@ -54,6 +54,33 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(WSTR dir, size_t size)
+{
+    size_t len = wcslen(dir);
+
+    if (dir[len - 1] != '\\')
+    {
+        if (len + 1 > size)
+        {
+            return FALSE;
+        }
+        dir[len] = '\\';
+        dir[len + 1] = '\0';
+    }
+
+    return TRUE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +117,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +137,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email

to look at the new patch set (#2).

Change subject: iservice: make sure directories have trailing \
......................................................................

iservice: make sure directories have trailing \

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

---
M src/openvpnserv/common.c

1 file changed, 33 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/2

src/openvpnserv/common.c +33 -6
index d25d9c0..4202fb0 100644
@@ -54,6 +54,33 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(PWSTR dir, size_t size)
+{
+    size_t len = wcslen(dir);
+
+    if (dir[len - 1] != '\\')
+    {
+        if (len + 1 > size)
+        {
+            return FALSE;
+        }
+        dir[len] = '\\';
+        dir[len + 1] = '\0';
+    }
+
+    return TRUE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +117,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +137,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos.

stipa has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing \
......................................................................

Patch Set 2: Code-Review-1

(1 comment)

Patchset:

PS2:
Why not https://learn.microsoft.com/en-us/windows/win32/api/pathcch/nf-pathcch-pathcchaddbackslashex ?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Mon, 03 Nov 2025 08:30:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos, stipa.

Hello flichtenheld, plaisthos, stipa,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email

to look at the new patch set (#3).

The following approvals got outdated and were removed:
Code-Review-1 by stipa

Change subject: iservice: make sure directories have trailing \
......................................................................

iservice: make sure directories have trailing \

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

---
M src/openvpnserv/common.c

1 file changed, 24 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/3

src/openvpnserv/common.c +24 -6
index d25d9c0..b2225f8 100644
@@ -20,6 +20,8 @@
  *  with this program; if not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <pathcch.h>
+
 #include "service.h"
 #include "validate.h"
 #include "eventmsg.h"
@@ -54,6 +56,22 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(PWSTR dir, size_t size)
+{
+    HRESULT res = PathCchAddBackslash(dir, size);
+    return res == S_OK || res == S_FALSE ? TRUE : FALSE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +108,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +128,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos, stipa.

cron2 has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing \
......................................................................

Patch Set 5: Code-Review-2

(2 comments)

Patchset:

PS5:
does not compile on windows

File src/openvpnserv/common.c:

http://gerrit.openvpn.net/c/openvpn/+/1336/comment/5866c2c1_a20cb45c?usp=email :
PS5, Line 71: return res == S_OK || res == S_FALSE ? TRUE : FALSE;
please use braces here so it's clear to the casual reader what part of the boolean goes into the ternary operator

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 5
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 07 Nov 2025 08:14:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos, stipa.

cron2 has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing \
......................................................................

Patch Set 6: Code-Review-2

(1 comment)

Patchset:

PS6:
It still fails compilation... googling for the error message led me here

https://stackoverflow.com/questions/4845198/fatal-error-no-target-architecture-in-visual-studio

which reads as if windows header files need to come after <windows.h>, never standalone.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 6
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 07 Nov 2025 22:44:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.

d12fk has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing \
......................................................................

Patch Set 6:

(1 comment)

Patchset:

PS6:

Quoted 1 line

It still fails compilation... googling for the error message led me here […]

Builds fine when cross-compiling with mingw 🤌

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 6
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 07 Nov 2025 22:47:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.

Hello cron2, flichtenheld, plaisthos, stipa,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email

to look at the new patch set (#7).

Change subject: iservice: make sure directories have trailing \
......................................................................

iservice: make sure directories have trailing \

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

---
M src/openvpnserv/common.c

1 file changed, 24 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/7

src/openvpnserv/common.c +24 -6
index d25d9c0..b1c89c9 100644
@@ -24,6 +24,8 @@
 #include "validate.h"
 #include "eventmsg.h"
 
+#include <pathcch.h>
+
 LPCWSTR service_instance = L"";
 static wchar_t win_sys_path[MAX_PATH];
 
@@ -54,6 +56,22 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(PWSTR dir, size_t size)
+{
+    HRESULT res = PathCchAddBackslash(dir, size);
+    return (res == S_OK || res == S_FALSE) ? TRUE : FALSE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +108,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +128,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 7
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.

d12fk has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing \
......................................................................

Patch Set 7:

(1 comment)

File src/openvpnserv/common.c:

http://gerrit.openvpn.net/c/openvpn/+/1336/comment/a2b062ca_547b7ce3?usp=email :
PS5, Line 71: return res == S_OK || res == S_FALSE ? TRUE : FALSE;

Quoted 1 line

please use braces here so it's clear to the casual reader what part of the boolean goes into the ter […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 7
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 07 Nov 2025 23:46:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos, stipa.

cron2 has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing \
......................................................................

Patch Set 7: Code-Review+1

(1 comment)

Patchset:

PS7:
my concerns have been addressed, thanks.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 7
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Sat, 08 Nov 2025 10:27:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#11 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos.

stipa has posted comments on this change by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing \
......................................................................

Patch Set 7: Code-Review+2

(1 comment)

Patchset:

PS7:
LGTM

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 7
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Sun, 09 Nov 2025 15:25:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#12 lore raw

PATCH v7 1/1 iservice: make sure directories have trailing \

In reply to a message not in the archive

From: Heiko Hund <[email protected]...>

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1336
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1336
This mail reflects revision 7 of this Change.

Acked-by according to Gerrit (reflected above):
Lev Stipakov <[email protected]...>

src/openvpnserv/common.c +24 -6
index d25d9c0..b1c89c9 100644
@@ -24,6 +24,8 @@
 #include "validate.h"
 #include "eventmsg.h"
 
+#include <pathcch.h>
+
 LPCWSTR service_instance = L"";
 static wchar_t win_sys_path[MAX_PATH];
 
@@ -54,6 +56,22 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(PWSTR dir, size_t size)
+{
+    HRESULT res = PathCchAddBackslash(dir, size);
+    return (res == S_OK || res == S_FALSE) ? TRUE : FALSE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +108,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +128,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }
#13 lore raw

[Openvpn-devel] [PATCH applied] Re: iservice: make sure directories have trailing backslash

Stared at the code, it does what it says on the lid, though I wonder if that's a reasonable thing to do in all cases... "log_dir" seems to be fully unused in the code base, and "bin_dir" is only used once (to call tapctl), and that one has two backslashes now, as the

src/openvpnserv/interactive.c: if (swprintf_s(cmd, _countof(cmd), L"%s\\tapctl.exe", settings.bin_dir) < 0)

adds another one... but it will not hurt, as far as I understand.

I have changed the Subject: to not end in a single "\", because that upsets half my scripts later on :-)

Your patch has been applied to the master branch.

commit 985f4eaeccf0d3f9d833f3271d88634e237d7cd5

Author: Heiko Hund
Date:   Sun Nov 9 16:44:31 2025 +0100
     iservice: make sure directories have trailing backslash

     Signed-off-by: Heiko Hund <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1336
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg34285.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#14 lore raw
In reply to a message not in the archive

Attention is currently required from: d12fk, flichtenheld, plaisthos.

Hello cron2, flichtenheld, plaisthos, stipa,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email

to look at the new patch set (#8).

The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied now.

Change subject: iservice: make sure directories have trailing \
......................................................................

iservice: make sure directories have trailing \

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

---
M src/openvpnserv/common.c

1 file changed, 24 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/8

src/openvpnserv/common.c +24 -6
index d25d9c0..b1c89c9 100644
@@ -24,6 +24,8 @@
 #include "validate.h"
 #include "eventmsg.h"
 
+#include <pathcch.h>
+
 LPCWSTR service_instance = L"";
 static wchar_t win_sys_path[MAX_PATH];
 
@@ -54,6 +56,22 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(PWSTR dir, size_t size)
+{
+    HRESULT res = PathCchAddBackslash(dir, size);
+    return (res == S_OK || res == S_FALSE) ? TRUE : FALSE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +108,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +128,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 8
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>

#15 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: iservice: make sure directories have trailing backslash

In reply to a message not in the archive

cron2 has uploaded a new patch set (#9) to the change originally created by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

The following approvals got outdated and were removed:
Code-Review+1 by cron2, Code-Review+2 by stipa

Change subject: iservice: make sure directories have trailing backslash
......................................................................

iservice: make sure directories have trailing backslash

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1336
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34285.html

---
M src/openvpnserv/common.c

1 file changed, 24 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1336/9

src/openvpnserv/common.c +24 -6
index d25d9c0..b1c89c9 100644
@@ -24,6 +24,8 @@
 #include "validate.h"
 #include "eventmsg.h"
 
+#include <pathcch.h>
+
 LPCWSTR service_instance = L"";
 static wchar_t win_sys_path[MAX_PATH];
 
@@ -54,6 +56,22 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(PWSTR dir, size_t size)
+{
+    HRESULT res = PathCchAddBackslash(dir, size);
+    return (res == S_OK || res == S_FALSE) ? TRUE : FALSE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +108,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +128,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 9
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#16 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: iservice: make sure directories have trailing backslash

In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email )

Change subject: iservice: make sure directories have trailing backslash
......................................................................

iservice: make sure directories have trailing backslash

At least in the case of the config dir this matters, since the value is used to validate input data for the interactive service. A missing \
at the end would allow a string compare to succeed, if the last element of the path to compare starts with the same substring. The trailing slash ensures that the last element of a path must match completely.

Change-Id If28e66fcc3493821f78fd14d432b22b996918e8f

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1336
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34285.html

---
M src/openvpnserv/common.c

1 file changed, 24 insertions(+), 6 deletions(-)
src/openvpnserv/common.c +24 -6
index d25d9c0..b1c89c9 100644
@@ -24,6 +24,8 @@
 #include "validate.h"
 #include "eventmsg.h"
 
+#include <pathcch.h>
+
 LPCWSTR service_instance = L"";
 static wchar_t win_sys_path[MAX_PATH];
 
@@ -54,6 +56,22 @@
 }
 
 
+/**
+ * Make sure that a dir path ends with a backslash.
+ * If it doesn't, a \ is added to the end of the path, if there's room in the buffer.
+ *
+ * @param dir       pointer to the wide dir path string buffer
+ * @param size      maximum number of wide chars the dir path buffer
+ * @return BOOL to indicate success or failure
+ */
+static BOOL
+ensure_trailing_backslash(PWSTR dir, size_t size)
+{
+    HRESULT res = PathCchAddBackslash(dir, size);
+    return (res == S_OK || res == S_FALSE) ? TRUE : FALSE;
+}
+
+
 DWORD
 GetOpenvpnSettings(settings_t *s)
 {
@@ -90,16 +108,16 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\config", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\config\\", install_path);
     error = GetRegString(key, L"config_dir", s->config_dir, sizeof(s->config_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->config_dir, _countof(s->config_dir)))
     {
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\bin", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\bin\\", install_path);
     error = GetRegString(key, L"bin_dir", s->bin_dir, sizeof(s->bin_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->bin_dir, _countof(s->bin_dir)))
     {
         goto out;
     }
@@ -110,9 +128,9 @@
         goto out;
     }
 
-    swprintf(default_value, _countof(default_value), L"%ls\\log", install_path);
+    swprintf(default_value, _countof(default_value), L"%ls\\log\\", install_path);
     error = GetRegString(key, L"log_dir", s->log_dir, sizeof(s->log_dir), default_value);
-    if (error != ERROR_SUCCESS)
+    if (error != ERROR_SUCCESS || !ensure_trailing_backslash(s->log_dir, _countof(s->log_dir)))
     {
         goto out;
     }

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1336?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: If28e66fcc3493821f78fd14d432b22b996918e8f
Gerrit-Change-Number: 1336
Gerrit-PatchSet: 9
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-Reviewer: stipa <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>